//
//  RouterManager.m
//  PosApp
//
//  Created by HippieFox on 2019/8/2.
//  Copyright © 2019 李英新. All rights reserved.
//

#import "RouterManager.h"

@implementation RouterManager
+ (NSNotificationName )alipaySuccessNotificationName{
    return  @"NOTIFICATION_ALIPAY_SUCCESS";
}

+ (void)updateZunXiang{
    
    
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
    [dic setObject:KUseriPhone forKey:@"phone"];
    
    [MainObjectWay PostWithMethod:@"SVIP" andAction:@"OtherVip" andAddParam:YES parameters:dic success:^(id responseObject) {
        
        NSLog(@"返回数据 = %@",responseObject);
        if ([MainObjectWay IsSucceedWithCode:responseObject[@"code"]]) {
            
            NSString * appScheme = @"2018041960010143";
            NSString * orderString = responseObject[@"data"];
            
            [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
                NSLog(@"支付宝结果 === %@",resultDic);
            }];
        }else{
            
            NSString * AlertStr = [NSString stringWithFormat:@"%@",responseObject[@"msg"]];
            UIAlertController * AlertC = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
            
            //修改message
            NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:AlertStr];
            [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, AlertStr.length)];
            [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, AlertStr.length)];
            [AlertC setValue:alertControllerMessageStr forKey:@"attributedMessage"];
            
            [AlertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"");
            }]];
            
//            [self presentViewController:AlertC animated:YES completion:nil];
            
        }
    } failure:^(NSError *error) {
        NSLog(@"错误信息 = %@",error);
    }];
}


+ (void)fetchQuan:(void (^)(NSInteger maxCount))cb{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
    [dic setObject:KUseriPhone forKey:@"phone"];
    
    [MainObjectWay PostWithMethod:@"getUserDeduction" andAction:@"User" andAddParam:YES parameters:dic success:^(id responseObject) {
        NSString * count = responseObject[@"data"][@"count"];
        cb([count integerValue]);
        NSLog(@":::%@",count);
    } failure:^(NSError *error) {
        
    }];
}
@end
